package com.wlzg.collectiontool.view

import android.content.Context
import android.view.View
import com.bumptech.glide.Glide
import com.lxj.xpopup.core.PositionPopupView
import com.wlzg.collectiontool.R
import kotlinx.android.synthetic.main.image_dia.view.*

class ImageDia(var mContext: Context, var guandianDia: GuandianDia) : PositionPopupView(mContext),
    View.OnClickListener {
    private var index: Int = 0
    var imageList=ArrayList<String>()

    override fun getImplLayoutId(): Int {
        return R.layout.image_dia
    }

    override fun onCreate() {
        super.onCreate()
        up.setOnClickListener(this)
        down.setOnClickListener(this)
        delete.setOnClickListener(this)
        exit.setOnClickListener(this)
        diss.setOnClickListener(this)
        if (imageList.size > 0) {

            Glide.with(this).load(imageList[index]).into(image)
        }
    }

    override fun onClick(p0: View?) {
        when (p0?.id) {
            R.id.up -> {
                if (index > 0) {
                    index -= 1
                    Glide.with(this).load(imageList[index]).into(image)
                }
            }
            R.id.down -> {
                if (imageList.size > 0 && index < imageList.size - 1) {
                    index = +1
                    Glide.with(this).load(imageList[index]).into(image)
                }
            }
            R.id.delete -> {
                if (imageList.size > 0) {
                    imageList.removeAt(index)
                    if(index==0){
                       image.setImageDrawable(null)
                    }
                    else if (index < imageList.size - 1) {
                        Glide.with(this).load(imageList[index]).into(image)
                    } else {
                        Glide.with(this).load(imageList[index - 1]).into(image)
                    }
                }
            }
            R.id.exit -> {
                this.dismiss()
            }
            R.id.diss -> {
                this.dismiss()
            }
        }

    }
}